﻿/******************************************************   
创建者: 梁家健
创建时间: 2017-04-12
修改:
修改时间: 
功能: 小品类宽度满足度
 ******************************************************/

using com.nm.ApiServer;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using com.nm.library.Helper;
using george.Data;
using Nancy.Extensions;
using NHibernateVertica;
using PlanAPI.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using com.nm.library;
using VerticaAPI;

namespace PlanAPI
{
    [Description("小品类宽度满足度")]
    public class PLItemSkcCodeDetailHandler : BaseHandler
    {
        public VerticaDataHelper Helper { get; set; } = new VerticaDataHelper();

        /// Writer：梁家健
        /// Create Date：2017-04-12
        [MustLogin]
        [Description("企划-小品类SKC数量列表")]
        [ReturnType(typeof(PaperData<PLItemSkcOperLogModel.ListModel>))]
        public ApiResult GetPLItemSkcOperLogList([ParamDescription("企划年")] long Yearv , 
            [ParamDescription("企划月")] long Monthv , [ParamDescription("周")] long Weekv ,
            [ParamDescription("类别")] string KindID = "", [ParamDescription("系列")] string SeriesID = "",
            [ParamDescription("商品层")] string MaterialProperty = "", [ParamDescription("品类")]string ModelID = "")
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                var dt = ReturnPLModelProcessList(Yearv, Monthv, Weekv, KindID, SeriesID, MaterialProperty, ModelID);
                var result = ModelConvertHelper<PLItemSkcOperLogModel.ListModel>.ConvertToModel(dt);
                return Success(result);
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }

        /// <summary>
        /// 企划-小品类SKC数量列表
        /// </summary>
        /// <param name="Weekv"></param>
        /// <param name="KindID"></param>
        /// <param name="SeriesID"></param>
        /// <param name="MaterialProperty"></param>
        /// <param name="ModelID"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-12
        public DataTable ReturnPLModelProcessList(long Yearv, long Monthv, long Weekv, string KindID, string SeriesID, string MaterialProperty, string ModelID)
        {
            try
            {
                var sql = $@"SELECT  skcLog.Yearv ,
        skcLog.Monthv ,
        skcLog.Weekv ,
        skcLog.KindID ,
        skcLog.SeriesID ,
        skcLog.MaterialProperty ,
        skcLog.ModelID ,
        skcLog.ItemID ,
        skcLog.FinishFalg ,
        lim.PurLimit ,
        item.ItemName ,
        MAX(pcs.CkSKCQty) AS MaxSKCQty ,
        det.isCreate
FROM    ngoods.ngoods_PL_Item_SkcOperLog skcLog
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Bas_ItemPurLimit
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) lim ON skcLog.KindID = lim.KindID
                           AND skcLog.ModelID = lim.ModelID
                           AND skcLog.ItemID = lim.ItemID
                           AND skcLog.ExtrSource = lim.ExtrSource
                           AND skcLog.CompanyID = lim.CompanyID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Item_SkcPcs
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                  ) pcs ON skcLog.Yearv = pcs.Yearv
                           AND skcLog.Monthv = pcs.Monthv
                           AND skcLog.Weekv = pcs.Weekv
                           AND skcLog.KindID = pcs.KindID
                           AND skcLog.SeriesID = pcs.SeriesID
                           AND skcLog.MaterialProperty = pcs.MaterialProperty
                           AND skcLog.ModelID = pcs.ModelID
                           AND skcLog.ItemID = pcs.ItemID
                           AND skcLog.ExtrSource = pcs.ExtrSource
                           AND skcLog.CompanyID = pcs.CompanyID
        INNER JOIN ( SELECT *
                     FROM   nods.nods_erp_SD_Mat_Item
                     WHERE  ExtrSource = '{UserInfo.UserExtrSource}'
                   ) item ON skcLog.ItemID = item.ItemID
                             AND skcLog.ExtrSource = item.ExtrSource
        LEFT JOIN ( SELECT  COUNT(1) AS isCreate ,
                            ExtrSource ,
                            CompanyID ,
                            Yearv ,
                            Monthv ,
                            Weekv ,
                            KindID ,
                            SeriesID ,
                            MaterialProperty ,
                            ModelID ,
                            ItemID
                    FROM    ngoods.ngoods_PL_Item_SkcCodeDetail
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                            AND Yearv = '{Yearv}'
                            AND Monthv = '{Monthv}'
                            AND Weekv = '{Weekv}'
							{(string.IsNullOrEmpty(KindID) ? "" : $@" and KindID='{KindID}' ")}
							{(string.IsNullOrEmpty(SeriesID) ? "" : $@" and SeriesID='{SeriesID}' ")}
							{(string.IsNullOrEmpty(MaterialProperty) ? "" : $@" and MaterialProperty='{MaterialProperty}' ")}
							{(string.IsNullOrEmpty(ModelID) ? "" : $@" and ModelID='{ModelID}' ")}
                    GROUP BY ExtrSource ,
                            CompanyID ,
                            Yearv ,
                            Monthv ,
                            Weekv ,
                            KindID ,
                            SeriesID ,
                            MaterialProperty ,
                            ModelID ,
                            ItemID
                  ) det ON skcLog.ExtrSource = det.ExtrSource
                           AND skcLog.CompanyID = det.CompanyID
                           AND skcLog.Yearv = det.Yearv
                           AND skcLog.Monthv = det.Monthv
                           AND skcLog.Weekv = det.Weekv
                           AND skcLog.KindID = det.KindID
                           AND skcLog.SeriesID = det.SeriesID
                           AND skcLog.MaterialProperty = det.MaterialProperty
                           AND skcLog.ModelID = det.ModelID
                           AND skcLog.ItemID = det.ItemID
WHERE   skcLog.ExtrSource = '{UserInfo.UserExtrSource}'
        AND skcLog.CompanyID = '{UserInfo.UserCompanyId}'
        AND skcLog.Yearv = '{Yearv}'
        AND skcLog.Monthv = '{Monthv}'
        AND skcLog.Weekv = '{Weekv}'
		{(string.IsNullOrEmpty(KindID) ? "" : $@" and skcLog.KindID='{KindID}' ")}
		{(string.IsNullOrEmpty(SeriesID) ? "" : $@" and skcLog.SeriesID='{SeriesID}' ")}
		{(string.IsNullOrEmpty(MaterialProperty) ? "" : $@" and skcLog.MaterialProperty='{MaterialProperty}' ")}
		{(string.IsNullOrEmpty(ModelID) ? "" : $@" and skcLog.ModelID='{ModelID}' ")}
GROUP BY skcLog.Yearv ,
        skcLog.Monthv ,
        skcLog.Weekv ,
        skcLog.KindID ,
        skcLog.SeriesID ,
        skcLog.MaterialProperty ,
        skcLog.ModelID ,
        skcLog.ItemID ,
        skcLog.FinishFalg ,
        lim.PurLimit ,
        item.ItemName ,
        det.isCreate
ORDER BY skcLog.Yearv DESC ,
        skcLog.Monthv DESC ,
        skcLog.Weekv ,
        skcLog.KindID ,
        skcLog.SeriesID ,
        skcLog.MaterialProperty ,
        skcLog.ModelID ,
        skcLog.ItemID";
                var cmd = Helper.GetSqlStringCommand(sql);
                return Helper.ExecuteDataTable(cmd);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// Writer：梁家健
        /// Create Date：2017-04-12
        [JsonType]
        [MustLogin]
        [Description("生成企划周店铺小品类SKC起订量")]
        [ReturnType(typeof(int), "0-成功")]
        public ApiResult CreatePLItemSkcCodeDetail([ParamDescription("小品类")] PLItemSkcCodeDetailModel.CreModel param)
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                var sql = $@"DELETE  FROM ngoods.ngoods_PL_Item_SkcCodeDetail
WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
        AND CompanyID = '{UserInfo.UserCompanyId}'
        AND Yearv = '{{0}}'
        AND Monthv = '{{1}}'
        AND Weekv = '{{2}}' 
		{{3}} 
		{{4}} 
		{{5}} 
		{{6}}";
                var pcsList = new PLItemSkcPcsHandler().ReturnAllPLItemSkcPcsList(param.Yearv, param.Monthv, param.Weekv,
                    param.KindID, param.SeriesID, param.MaterialProperty, param.ItemIDList);
                var gvHandler = new DwGlobalVariableHandler();
                var itemDic = gvHandler.ReturnOdsErpSDMatItem().ToDictionary(d => d.ItemID, d => d.ItemCode);
                var seriesDic = gvHandler.ReturnOdsErpSdMatSeries().ToDictionary(d => d.SeriesID, d => d.SeriesCode);
                var kindDic = gvHandler.ReturnOdsErpSdMatKind().ToDictionary(d => d.KindID, d => d.KindCode);
                var cmdList = new List<CommandInfo>()
                {
                    new CommandInfo()
                    {
                        CommandText = string.Format(sql, param.Yearv, param.Monthv, param.Weekv,
                            string.IsNullOrEmpty(param.KindID) ? "" : $" and KindID='{param.KindID}' ",
                            string.IsNullOrEmpty(param.SeriesID) ? "" : $" and SeriesID='{param.SeriesID}' ",
                            string.IsNullOrEmpty(param.MaterialProperty)
                                ? ""
                                : $" and MaterialProperty='{param.MaterialProperty}' ",
                            string.IsNullOrEmpty(param.ItemIDList) ? "" : $" and ItemID in ({param.ItemIDList}) ")
                    },
                };
                var list = new List<PLItemSkcCodeDetailModel.NeceModel>();
                foreach (var item in pcsList)
                {
                    var materialProperty = "Q";
                    switch (item.MaterialProperty)
                    {
                        case "基本款":
                            materialProperty = "J";
                            break;
                        case "流行款":
                            materialProperty = "L";
                            break;
                        case "形象款":
                            materialProperty = "X";
                            break;
                        default:
                            materialProperty = "Q";
                            break;
                    }
                    for (var i = 1; i <= item.CkSKCQty; i++)
                    {
                        var model = new PLItemSkcCodeDetailModel.NeceModel()
                        {
                            CompanyID = UserInfo.UserCompanyId,
                            ExtrSource = UserInfo.UserExtrSource,
                            Yearv = param.Yearv,
                            Monthv = param.Monthv,
                            Weekv = param.Weekv,
                            ParentAreaID = item.ParentAreaID,
                            ShopID = item.ShopID,
                            KindID = item.KindID,
                            SeriesID = item.SeriesID,
                            MaterialProperty = item.MaterialProperty,
                            ModelID = item.ModelID,
                            ItemID = item.ItemID,
                            SKCCode =
                                $"{param.Yearv%100}{(param.Weekv >= 10 ? param.Weekv.ToString() : $"0{param.Weekv}")}{kindDic[item.KindID]}{seriesDic[item.SeriesID]}{itemDic[item.ItemID]}{materialProperty}-{(i >= 100 ? i.ToString() : (i >= 10 ? $"0{i}" : $"00{i}"))}",
                        };
                        list.Add(model);
                    }
                }
                var dt = DataTableHelper.LinqToDataTable(list.ToList().DistinctBy(d => new
                {
                    d.Yearv,
                    d.Monthv,
                    d.Weekv,
                    d.ParentAreaID,
                    d.ShopID,
                    d.KindID,
                    d.SeriesID,
                    d.MaterialProperty,
                    d.ModelID,
                    d.ItemID,
                    d.SKCCode
                }));
                Helper.ExecuteSqlTran(cmdList, dt, "ngoods.ngoods_PL_Item_SkcCodeDetail");
                return Success(0);
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }

        /// Writer：梁家健
        /// Create Date：2017-04-12
        [MustLogin]
        [Description("企划周店铺小品类SKC起订量")]
        [ReturnType(typeof(IList<PLItemSkcCodeDetailModel.NeceModel>))]
        public ApiResult GetPLItemSkcCodeDetailList([ParamDescription("企划年")] long Yearv, 
            [ParamDescription("企划月")] long Monthv, [ParamDescription("企划周")] long Weekv, 
            [ParamDescription("类别")] string KindID, [ParamDescription("系列")] string SeriesID ,
            [ParamDescription("商品层")] string MaterialProperty , [ParamDescription("小品类ID")] string ItemID)
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                var titleList = ReturnPLItemSkcCodeDetailTitle(Yearv, Monthv, Weekv, KindID, SeriesID, MaterialProperty, ItemID);
                var list = ReturnPLItemSkcCodeDetailList(Yearv, Monthv, Weekv, KindID, SeriesID, MaterialProperty, ItemID)
                    .GroupBy(d =>
                    d.Yearv + "_" +
                    d.Monthv + "_" +
                    d.Weekv + "_" +
                    d.ParentAreaID + "_" +
                    d.ShopID + "_" +
                    d.KindID + "_" +
                    d.SeriesID + "_" +
                    d.MaterialProperty + "_" +
                    d.ModelID + "_" +
                    d.ItemID);
                var result = new PLItemSkcCodeDetailModel.ShowModel()
                {
                    list = list.ToList(),
                    titleList = titleList,
                };
                return Success(result);
            }
            catch (Exception ex)
            {
                return Error(ex.Message);
            }
        }

        /// <summary>
        /// 返回企划周店铺小品类SKC起订量
        /// </summary>
        /// <param name="Yearv"></param>
        /// <param name="Monthv"></param>
        /// <param name="ItemID"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-12
        public IList<PLItemSkcCodeDetailModel.ListModel> ReturnPLItemSkcCodeDetailList(long Yearv, long Monthv, long Weekv, string KindID, string SeriesID, string MaterialProperty, string ItemID)
        {
            try
            {
                var sql = $@"SELECT  det.* ,
        shop.ShopName ,
        pcs.CkSKCQty ,
        tre.CKMoveDeepQty
FROM    ngoods.ngoods_PL_Item_SkcCodeDetail det
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_Item_SkcPcs
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                            AND Yearv = '{Yearv}'
                            AND Monthv = '{Monthv}'
                            AND Weekv = '{Weekv}'
                            AND ItemID = '{ItemID}'
                            AND KindID = '{KindID}'
                            AND SeriesID = '{SeriesID}'
                            AND MaterialProperty = '{MaterialProperty}'
                  ) pcs ON det.ExtrSource = pcs.ExtrSource
                           AND det.CompanyID = pcs.CompanyID
                           AND det.Yearv = pcs.Yearv
                           AND det.Monthv = pcs.Monthv
                           AND det.Weekv = pcs.Weekv
                           AND det.ParentAreaID = pcs.ParentAreaID
                           AND det.ShopID = pcs.ShopID
                           AND det.KindID = pcs.KindID
                           AND det.SeriesID = pcs.SeriesID
                           AND det.MaterialProperty = pcs.MaterialProperty
                           AND det.ModelID = pcs.ModelID
                           AND det.ItemID = pcs.ItemID
        LEFT JOIN ( SELECT  *
                    FROM    ngoods.ngoods_PL_ShopMSaleTrend
                    WHERE   ExtrSource = '{UserInfo.UserExtrSource}'
                            AND CompanyID = '{UserInfo.UserCompanyId}'
                            AND Yearv = '{Yearv}'
                            AND Monthv = '{Monthv}'
                            AND ItemID = '{ItemID}'
                            AND KindID = '{KindID}'
                            AND SeriesID = '{SeriesID}'
                            AND MaterialProperty = '{MaterialProperty}'
                  ) tre ON det.ExtrSource = tre.ExtrSource
                           AND det.CompanyID = tre.CompanyID
                           AND det.Yearv = tre.Yearv
                           AND det.Monthv = tre.Monthv
                           AND det.ParentAreaID = tre.ParentAreaID
                           AND det.ShopID = tre.ShopID
                           AND det.KindID = tre.KindID
                           AND det.SeriesID = tre.SeriesID
                           AND det.MaterialProperty = tre.MaterialProperty
                           AND det.ModelID = tre.ModelID
                           AND det.ItemID = tre.ItemID
        INNER JOIN ndw.ndw_Shop shop ON det.ShopID = shop.ShopID
WHERE   det.ExtrSource = '{UserInfo.UserExtrSource}'
        AND det.CompanyID = '{UserInfo.UserCompanyId}'
        AND det.Yearv = '{Yearv}'
        AND det.Monthv = '{Monthv}'
        AND det.Weekv = '{Weekv}'
        AND det.ItemID = '{ItemID}'
        AND det.KindID = '{KindID}'
        AND det.SeriesID = '{SeriesID}'
        AND det.MaterialProperty = '{MaterialProperty}'
ORDER BY det.Yearv DESC ,
        det.Monthv DESC ,
        det.Weekv ,
        det.ParentAreaID ,
        det.ShopID ,
        det.KindID ,
        det.SeriesID ,
        det.MaterialProperty ,
        det.ModelID ,
        det.ItemID";
                var cmd = Helper.GetSqlStringCommand(sql);
                var dt = Helper.ExecuteDataTable(cmd);
                return ModelConvertHelper<PLItemSkcCodeDetailModel.ListModel>.ConvertToModel(dt);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// 返回企划周店铺小品类SKC起订量表头
        /// </summary>
        /// <param name="Yearv"></param>
        /// <param name="Monthv"></param>
        /// <param name="Weekv"></param>
        /// <param name="ItemID"></param>
        /// <returns></returns>
        /// Writer：梁家健
        /// Create Date：2017-04-13
        public IList<PLItemSkcCodeDetailModel.TitleModel> ReturnPLItemSkcCodeDetailTitle(long Yearv, long Monthv, long Weekv, string KindID, string SeriesID, string MaterialProperty, string ItemID)
        {
            try
            {
                var sql = $@"SELECT  det.SKCCode
FROM    ngoods.ngoods_PL_Item_SkcCodeDetail det
WHERE   det.ExtrSource = '{UserInfo.UserExtrSource}'
        AND det.CompanyID = '{UserInfo.UserCompanyId}'
        AND det.Yearv = '{Yearv}'
        AND det.Monthv = '{Monthv}'
        AND det.Weekv = '{Weekv}'
        AND det.ItemID = '{ItemID}'
        AND det.KindID = '{KindID}'
        AND det.SeriesID = '{SeriesID}'
        AND det.MaterialProperty = '{MaterialProperty}'
GROUP BY det.SKCCode
ORDER BY det.SKCCode";
                var cmd = Helper.GetSqlStringCommand(sql);
                var dt = Helper.ExecuteDataTable(cmd);
                return ModelConvertHelper<PLItemSkcCodeDetailModel.TitleModel>.ConvertToModel(dt);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// Writer：梁家健
        /// Create Date：2017-04-13
        [JsonType]
        [MustLogin]
        [Description("修改企划-小品类SKC起订量列表")]
        [ReturnType(typeof(int), "0-成功")]
        public ApiResult UpdatePLItemSkcCodeDetail([ParamDescription("小品类SKC起订量")] PLItemSkcCodeDetailModel.ModifyModel param)
        {
            try
            {
                if (string.IsNullOrEmpty(UserInfo.UserCompanyId))
                {
                    return Error("该用户不属于任何公司!");
                }
                if (string.IsNullOrEmpty(UserInfo.UserExtrSource))
                {
                    return Error("该用户所在公司没有任何数据源!");
                }
                var sqlUpdateSkcCode = $@"UPDATE ngoods.ngoods_PL_Item_SkcCodeDetail
SET DeleteFlag='{{0}}'
where Yearv='{{1}}' and Monthv='{{2}}' and Weekv='{{3}}' and KindID='{{4}}' and SeriesID='{{5}}' and MaterialProperty='{{6}}' and ModelID='{{7}}' and ItemID='{{8}}' and SKCCode='{{9}}' and ExtrSource='{UserInfo.UserExtrSource}' and CompanyID='{UserInfo.UserCompanyId}' ";
                var sqlUpdateLog = $@"UPDATE ngoods.ngoods_PL_Item_SkcOperLog
SET FinishFalg='{{0}}'
where Yearv='{{1}}' and Monthv='{{2}}' and Weekv='{{3}}' and KindID='{{4}}' and SeriesID='{{5}}' and MaterialProperty='{{6}}' and ModelID='{{7}}' and ItemID='{{8}}' and ExtrSource='{UserInfo.UserExtrSource}' and CompanyID='{UserInfo.UserCompanyId}' ";
                var sqlUpdatePcs = $@"UPDATE goods.goods_PL_Item_SkcPcs
SET CkSKCQty='{{0}}'
where Yearv='{{1}}' and Monthv='{{2}}' and Weekv='{{3}}' and ParentAreaID='{{4}}' and ShopID='{{5}}' and KindID='{{6}}' and SeriesID='{{7}}' and MaterialProperty='{{8}}' and ModelID='{{9}}' and ItemID='{{10}}' and ExtrSource='{UserInfo.UserExtrSource}' and CompanyID='{UserInfo.UserCompanyId}' ";
                if (param == null) return Error("参数对象为空");
                if (param.list != null)
                {
                    var cmdList = new List<CommandInfo>() {
                        new CommandInfo()
                        {
                            CommandText = string.Format(sqlUpdateLog, "1", param.list.First().Yearv, param.list.First().Monthv, param.list.First().Weekv, param.list.First().KindID, param.list.First().SeriesID, param.list.First().MaterialProperty, param.list.First().ModelID, param.list.First().ItemID)
                        }
                    };
                    foreach (var item in param.list.DistinctBy(d => d.SKCCode))
                    {
                        var cmdLog = new CommandInfo()
                        {
                            CommandText =
                                string.Format(sqlUpdateSkcCode, item.DeleteFlag, item.Yearv, item.Monthv,
                                    item.Weekv, item.KindID, item.SeriesID, item.MaterialProperty, item.ModelID,
                                    item.ItemID, item.SKCCode)
                        };
                        cmdList.Add(cmdLog);
                    }
                    var group = param.list.GroupBy(d => new
                    {
                        d.Yearv,
                        d.Monthv,
                        d.Weekv,
                        d.ParentAreaID,
                        d.ShopID,
                        d.KindID,
                        d.SeriesID,
                        d.MaterialProperty,
                        d.ModelID,
                        d.ItemID
                    });
                    foreach(var item in group)
                    {
                        var sum = item.Select(d => d.DeleteFlag == 1).Count();
                        var cmdPcs = new CommandInfo()
                        {
                            CommandText =
                                string.Format(sqlUpdatePcs, item.First().CkSKCQty - sum, item.First().Yearv,
                                    item.First().Monthv, item.First().Weekv, item.First().ParentAreaID,
                                    item.First().ShopID, item.First().KindID, item.First().SeriesID,
                                    item.First().MaterialProperty, item.First().ModelID, item.First().ItemID)
                        };
                        cmdList.Add(cmdPcs);
                    }
                    Helper.ExecuteSqlTran(cmdList);
                }
                return Success(0);
            }
            catch(Exception ex)
            {
                return Error(ex.Message);
            }
        }
    }
}
